'use strict'
const mysql = require('mysql');
const pool = mysql.createPool({
  connectionLimit: 10,
  charset: 'utf8mb4_unicode_ci',
  timeout: 20000,
  host: '127.0.0.1',
  port: 3306,
  user: 'root',
  password: 'sunkuiwei',
});

module.exports.up = function (next) {
  const dbName = 'db12'

  pool.query("show databases", (err, databases) => {
    if (err) throw err.message;
    if (databases.some(db => db.Database === dbName)) return next();

    pool.query("CREATE DATABASE  `"+ dbName +"` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci", err => {
      if (err) throw err.message;
      next()
    });
  });
}
